import ToolRequest from '@/base/newToolAxios'
import RequestOption from '@/base/RequestOption'
import { getActToolUrl } from '@/base/constant'
import { TableData, TableReservation } from '@/type/table'

const tr = new ToolRequest()

export default class TableDao {
    /**
     * 获取所有桌位
     * @returns
     */
    async listAllTables() {
        const ro = new RequestOption()
        return await tr.get(getActToolUrl(), {
            action: 'listAllTables'
        }, ro)
    }

    /**
     * 获取桌位预定信息
     * @returns
     */
    async getTableReservations(tableId: number) {
        const ro = new RequestOption()
        return await tr.get(getActToolUrl(), {
            action: 'getTableReservations',
            tableId: tableId
        }, ro)
    }

    /**
     * 添加桌位预定
     * @returns
     */
    async addTableReservation(reservation: {
        tableId: number;
        dishId: number;
        quantity: number;
    }) {
        const ro = new RequestOption()
        return await tr.get(getActToolUrl(), {
            action: 'addTableReservation',
            tableId: reservation.tableId,
            dishId: reservation.dishId,
            quantity: reservation.quantity
        }, ro)
    }

    /**
     * 删除桌位预定
     * @returns
     */
    async deleteTableReservation(reservationId: number) {
        const ro = new RequestOption()
        return await tr.get(getActToolUrl(), {
            action: 'deleteTableReservation',
            reservationId: reservationId
        }, ro)
    }

    /**
     * 更新桌位状态
     * @returns
     */
    async updateTableStatus(tableId: number, status: number) {
        const ro = new RequestOption()
        return await tr.get(getActToolUrl(), {
            action: 'updateTableStatus',
            tableId: tableId,
            status: status
        }, ro)
    }

    /**
     * 预定桌位
     * @returns
     */
    async reserveTable(reservation: {
        tableId: number;
        customerName: string;
        customerPhone: string;
    }) {
        const ro = new RequestOption()
        return await tr.get(getActToolUrl(), {
            action: 'reserveTable',
            tableId: reservation.tableId,
            customerName: reservation.customerName,
            customerPhone: reservation.customerPhone
        }, ro)
    }

    /**
     * 结束预定
     * @returns
     */
    async endReservation(tableId: number) {
        const ro = new RequestOption()
        return await tr.get(getActToolUrl(), {
            action: 'endReservation',
            tableId: tableId
        }, ro)
    }

    /**
     * 执行预定（将桌位状态改为使用中）
     * @returns
     */
    async executeReservation(tableId: number) {
        const ro = new RequestOption()
        return await tr.get(getActToolUrl(), {
            action: 'executeReservation',
            tableId: tableId
        }, ro)
    }

    /**
     * 更新预定状态
     * @returns
     */
    async updateReservationStatus(reservationId: number, status: number) {
        const ro = new RequestOption()
        return await tr.get(getActToolUrl(), {
            action: 'updateReservationStatus',
            reservationId: reservationId,
            status: status
        }, ro)
    }
} 